//定义首页模块
Ext.ns('Welcome.Main') ;

/**
 * 主模块
 * @class Welcome.Main
 * @extends Ext.Panel
 */
Welcome.Main = Ext.extend(Ext.Panel,{
	 layout:'border',
	 iconCls: "ico-home",
	 border:false,
   	 autoScroll:true,
   	 split: true,
   	 title : '首页',
   	 width:'100%',
   	 initComponent : function() {
   	 	this.items = [new Welcome.Main.east(),new Welcome.Main.center()]
   		Welcome.Main.superclass.initComponent.call(this);
   	}
});

/**
 * 中心区域
 * @class Welcome.Main.center
 * @extends Ext.Panel
 */
Welcome.Main.center = Ext.extend(Ext.FormPanel,{
	 closable: true,
	 region:"center",
	 split: true,
	 layout:"form",
	 region : "center",
	 labelAlign:"right",
	 frame:true,
   	 initComponent : function() {
   	 	this.items = [{
   	 		padding:'30',
   	 		layout:'form',
   	 		width:'100%',
   	 		xtype:'panel',
   	 		items:[
   	 	{ 
   	 		anchor:"90%",
   	 		xtype:'combo',
   	 		hiddenName:'Event',
   	 		editable : false,
			triggerAction : 'all',
   	 		value:'ReceiveClusterIM',
   	 		store:[
   	 				['ReceiveClusterIM','群消息']
   	 			   ,['ReceiveNormalIM','好友消息']
   	 			  ]
   	 		,fieldLabel:'事件类型'
   	 	},{
   	 		xtype:'textfield',
   	 		anchor:"90%",
   	 		name:'Sender',
   	 		value:'261589289',
   	 		fieldLabel:'发送者QQ'
   	 	},{
   	 		xtype:'textfield',
   	 		anchor:"90%",
   	 		name:'ClusterNum',
   	 		value:'222048974',
   	 		fieldLabel:'QQ群号码'
   	 	},{
   	 		xtype:'textfield',
   	 		anchor:"90%",
   	 		name:'ApiPort',
   	 		value:'17998',
   	 		fieldLabel:'端口'
   	 	},{
   	 		xtype:'textarea',
   	 		anchor:"90%",
   	 		name:'Message',
   	 		value:'',
   	 		fieldLabel:'消息内容'
   	 	},{
			boxLabel:"Debug",
			name : 'debug',
			xtype : 'checkbox'
		}]
   	 	,buttonAlign :'center'
		,minButtonWidth:60
	   	,buttons:[{
			   		text:'发送',
			   		handler:function(btn){
	   					var form = btn.ownerCt.ownerCt.ownerCt.getForm();
	   					form.submit({
	   					method:'POST',
	   						url:'action.php?action=doEvent&api=true',
                //url:'http://127.0.0.1:3000',
	   						success:function(form,action) {
								var res = action.result;
	   							var messp =  btn.ownerCt.ownerCt.ownerCt.ownerCt.items.get(0);
	   							 btn.ownerCt.ownerCt.ownerCt.setMessage(res.info,messp);
	   						}
	   					});
			   		}
			   	},{
			   		text:'重置',
			   		handler:function(btn){
			   			btn.ownerCt.ownerCt.ownerCt.getForm().reset();
			   		}
			   	}]
   	 	}]
   		Welcome.Main.center.superclass.initComponent.call(this);
   	}
   	,setMessage:function(mess,p) {
   		if(!mess ||mess.trim()=="") {
   			mess="无消息返回~~";
   		}
   		mess = mess.replace(/[\n\r]/g,'<br/>');
   		mess = mess.replace(/\t/g,'	');
   		var messCom = p.el.dom.firstChild.firstChild.firstChild;
   		messCom.innerHTML += "<p><font color='#0000ff'>&nbsp;索妮娅：</font>"+mess+"</p>";
   		//messCom.scrollTop = scrollTop.scrollHeight;
   		//var d =  p.body.dom;
		messCom.scrollTop = messCom.scrollHeight - messCom.offsetHeight;
   	}
});


/**
 * 右方区域
 * @class Welcome.Main.east
 * @extends Ext.TabPanel
 */
Welcome.Main.east = Ext.extend(Ext.Panel,{
	 closable: true,
	 region:"east",
	 split: true,
   	 width:'40%',
   	 initComponent : function() {
		this.html = "<div style='height:100%;FONT-SIZE: 12px;COLOR: #ff0000;FONT-FAMILY: Geneva, Verdana, Arial, Helvetica;overflow-x:hidden;overflow-y:auto;'></div>";
   		Welcome.Main.east.superclass.initComponent.call(this);
   	},
   	bbar:[{
   		text:'清空',
   		iconCls: 'ico-task-delete',
   		handler:function(btn){
   			btn.ownerCt.ownerCt.el.dom.firstChild.firstChild.firstChild.innerHTML="";
   		}
   	}]
   	
});
